﻿using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace EyFramework.Maintenance
{
    public partial class MainBallControl : Control
    {
        public MainBallControl()
        {
            InitializeComponent();
        }

        protected override void OnPaint(PaintEventArgs pe)
        {
            base.OnPaint(pe);
            Graphics g = pe.Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            g.InterpolationMode = InterpolationMode.HighQualityBicubic;
            g.CompositingQuality = CompositingQuality.HighQuality;
            int incre = 0;

            Brush brush = new SolidBrush(Color.FromArgb(78, 78, 78));
            Rectangle rect = new Rectangle(0, 0, 38 + incre, 38 + incre);
            GraphicsPath path = CreateRoundedRectanglePath(rect, 19);
            g.FillPath(brush, path);

            brush = new SolidBrush(Color.WhiteSmoke);
            rect = new Rectangle(0, 0, 38 + incre, 38 + incre);
            path = CreateRoundedRectanglePath(rect, (38 + incre) / 2);
            g.FillPath(brush, path);

            brush = new SolidBrush(Color.FromArgb(37, 165, 78));
            g.FillEllipse(brush, 2, 2, 34 + incre, 34 + incre);

            brush = new SolidBrush(Color.FromArgb(0, 170, 191));//填充的颜色
            g.FillEllipse(brush, 4, 4, 30 + incre, 30 + incre);

            brush = new SolidBrush(Color.Snow);//填充的颜色
            g.DrawString("萧", new Font("微软雅黑", 12, FontStyle.Bold), brush, new PointF(9, 9));
            //g.DrawImage(global::Maintenance.Properties.Resources.app, 9, 9, 20, 20);
            g.Dispose();
        }

        public static GraphicsPath CreateRoundedRectanglePath(Rectangle rect, int cornerRadius)
        {
            int diameter = cornerRadius * 2;
            Rectangle arcRect = new Rectangle(rect.Location, new Size(diameter, diameter));
            GraphicsPath path = new GraphicsPath();

            // 左上角
            path.AddArc(arcRect, 180, 90);

            // 右上角
            arcRect.X = rect.Right - diameter;
            path.AddArc(arcRect, 270, 90);

            // 右下角
            arcRect.Y = rect.Bottom - diameter;
            path.AddArc(arcRect, 0, 90);

            // 左下角
            arcRect.X = rect.Left;
            path.AddArc(arcRect, 90, 90);
            path.CloseFigure();//闭合曲线
            return path;
        }
    }
}